#include "junix.h"

unsigned long  reg_file = 0;
unsigned long  dir_file = 0;

int count_file( const char *fpath,
		        const struct stat *sb,
				int flags)
{
	if( flags == FTW_F)
		++reg_file;
	else if( flags == FTW_D)
		++ dir_file;
	else 
		return 0;

	return 0;
}

int main(int argc, char **argv)
{
	if( argc != 2)
		err_quit("Usage:%s dir", argv[0]);

	if( ftw(argv[1], count_file, 0) == -1)
		err_sys("ftw");

	printf("reg file:%.lu\n", reg_file);
	printf("dir file:%.lu\n", dir_file);

    exit(0);
}

